package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.OrderRecords;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.OrderRecordsService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller
@RequestMapping("/orderRecordsController")
public class OrderRecordsController {
	@Resource
	OrderRecordsService orderRecordsService;
	@RequestMapping("/getAllOrderRecords")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<OrderRecords> getAllOrderRecords() throws Exception {
    	System.out.println("查询全部用户");
		return orderRecordsService.getAllOrderRecordss();
    }

	@RequestMapping("/deleteOrderRecordsByUshOrno/{ushOrno}")
	@ResponseBody
    public DTO<OrderRecords> deleteOrderRecordsByUshOrno(@PathVariable("ushOrno") String ushOrno) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(ushOrno+"删除用户");
    	return orderRecordsService.deleteOrderRecordsByUshOrno(ushOrno);
    }

	@RequestMapping("/updateOrderRecordsByUshOrno")
	@ResponseBody
	public DTO<OrderRecords> updateOrderRecordsByUshOrno(@RequestBody OrderRecords orderRecords) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改用户");
		return orderRecordsService.updateOrderRecordsByUshOrno(orderRecords);
	}


	@RequestMapping("/addOrderRecords")
	@ResponseBody
	public DTO<OrderRecords> addOrderRecords(@RequestBody OrderRecords orderRecords) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加用户");
		System.out.println(orderRecords);
 		return orderRecordsService.addOrderRecords(orderRecords);
	}
	@RequestMapping("/getOrderRecordsByPage")
	@ResponseBody
	public DTO<OrderRecords> getOrderRecordsByPage(PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页用户");
		String cacheId = "OrderRecordsByPage" + pageInfo.getCurrPage();//自编redis每页数据缓存的key
		System.out.println(cacheId);
		return pageInfo.getCurrPage() > 2 ? orderRecordsService.getOrderRecordsByPage(pageInfo) :
				orderRecordsService.getOrderRecordsByPage(pageInfo, cacheId);
	}

}